import { defineConfig } from "vite";
import Vue from "@vitejs/plugin-vue";
import Markdown from "vite-plugin-md";
import { generateModifyVars } from "./build/generate/generate-modify-vars";
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
import windiCSS from "vite-plugin-windicss";
import vueJsx from "@vitejs/plugin-vue-jsx";
import { resolve } from "path";

// https://vitejs.dev/config/
export default defineConfig({
  base: "/vben-ui/",
  plugins: [
    Vue({
      include: [/\.vue$/, /\.md$/],
    }),
    vueJsx(),
    Markdown(),
    createSvgIconsPlugin({
      iconDirs: [resolve(process.cwd(), "packages/assets/icons")],
      symbolId: "icon-[dir]-[name]",
    }),
    windiCSS({
      scan: {
        dirs: ["."], // 当前目录下所有文件
        fileExtensions: ["vue", "js", "ts"], // 同时启用扫描vue/js/ts
      },
    }),
  ],
  build: {
    rollupOptions: {
      // 请确保外部化那些你的库中不需要的依赖
      external: ["vue"],
      output: {
        // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
        globals: {
          vue: "Vue",
        },
      },
    },
    lib: {
      entry: "./packages/index.ts",
      name: "vben-ui",
      // formats: ["es", "umd"],
    },
  },
  resolve: {
    alias: {
      ["@"]: resolve(__dirname, "src"),
      ["$"]: resolve(__dirname, "packages"),
    },
  },

  css: {
    preprocessorOptions: {
      less: {
        modifyVars: generateModifyVars(),
        javascriptEnabled: true,
      },
    },
  },
});
